// import { request } from 'umi';
import { extend } from 'umi-request';
import {  message } from 'antd';
const request = extend({
  // prefix: "/api/v1",
  // suffix: ".json",
  timeout: 10000,
  headers: {
    'Content-Type': 'application/json',
    token: 'xxx',
  },
  // params: {
  //   token: "xxx" // 所有请求默认带上 token 参数
  // },
  errorHandler: function (error) {
    /* 异常处理 */
    message.error('连接服务器失败！请联系管理员')
  },
});

const env = process.env.NODE_ENV === 'development';

class ServicesBase {
  GET = (url: string, params = {}) => {
    return request(url, {
      params,
      method: 'GET',
    });
  };
  POST = (url: string, data = {}) => {
    return request(url, {
      data,
      method: 'POST',
    });
  };

  Request = (url: string, params = {}) => {
    if (env) {
      return this.GET(url, params);
    }
    return this.POST(url, params);
  };
}

export default ServicesBase;
